#ifndef CATEGORIESMODEL_H
#define CATEGORIESMODEL_H

#include <QSqlDatabase>
#include <QSqlQuery>
#include <QAbstractItemModel>
#include <QModelIndex>
#include <QVariant>

#include "categorieitem.h"

class CategoriesModel : public QAbstractItemModel
{
    Q_OBJECT

public:
    CategoriesModel(QSqlDatabase db, QObject *parent = 0);
    ~CategoriesModel();

    // Read
    QVariant data(const QModelIndex &index, int role) const;
    QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;

    QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
    QModelIndex parent(const QModelIndex &index) const;

    int rowCount(const QModelIndex &parent = QModelIndex()) const;
    int columnCount(const QModelIndex &parent = QModelIndex()) const;

    Qt::ItemFlags flags(const QModelIndex &index) const;

    void raffraichir(int root);



    // Write
    bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
    bool insertRows(int row, int count, const QModelIndex &parent);

    bool ordrePlus(const QModelIndex &index);
    bool ordreMoins(const QModelIndex &index);
    bool moveDown(const QModelIndex &index);
    bool moveUp(const QModelIndex &index);

    //bool removeRows(int position, int rows, const QModelIndex &parent = QModelIndex());

private:

    QSqlDatabase db;

    CategorieItem *racine;


signals:

public slots:

};

#endif // CATEGORIESMODEL_H
